﻿{% extends "base_cn.html" %}
{% block title %} -- {{ ShowUserInfo.NickName }}信息显示 {% endblock %}
{% block content %}


{% if ShowUserInfo %}

<script type="text/javascript" src="static/gears_init.js"></script>
<script type="text/javascript" src="http://www.google.cn/jsapi?key=ABQIAAAASxuhjqc-j0-xBqPZInKKfhToNW08s6aZzsYvqCmYymrddPgvJxSFfjpuxixLl2WrMuudrwyqAsajsg"></script>
<!--script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAASxuhjqc-j0-xBqPZInKKfhToNW08s6aZzsYvqCmYymrddPgvJxSFfjpuxixLl2WrMuudrwyqAsajsg"></script-->

<script type="text/javascript"> 
//    google.load("maps", "2"); 
    google.load("maps", "2", {"base_domain": "ditu.google.cn"}); 

    var geocoder = null;
    var map = null;

    var lat = null;
    var lon = null;
    var old_overlay = null;


{% if ShowUserInfo.Latitude %}
    lat = {{ ShowUserInfo.Latitude }};
{% endif %}

{% if ShowUserInfo.Longitude %}
    lon = {{ ShowUserInfo.Longitude }};
{% endif %}

    function handleError(positionError)
    {
	alert('获取本地坐标失败: ' + positionError.message);
    }

    function SetLocalPosition(position)
    {
	SetMapToLatAndLon(position.latitude, position.longitude);
    }

    function SetMapToLatAndLon(SetLat, SetLon)
    {
	lat = SetLat;
	lon = SetLon;

	if(null == map)
	{
	    map = new google.maps.Map2(document.getElementById("map_canvas"));
	    map.addControl(new GLargeMapControl());
	    map.addControl(new GMapTypeControl());
	}

	var current_location = new GLatLng(SetLat, SetLon);

	map.setCenter(current_location, 13); 

	var marker = new GMarker(current_location);
	if(null != old_overlay)
	{
	    map.removeOverlay(old_overlay);
	}

	map.addOverlay(marker);
	old_overlay = current_location;

	if(null == geocoder)
	{
	    geocoder = new GClientGeocoder();
	}
	geocoder.getLocations(current_location, ShowAddressAtPage);
    }

    function ShowAddressAtPage(response)
    {
	if(response && response.Status.code == 200)
	{
	    place = response.Placemark[0];
	    document.getElementById("human_readable").innerHTML = place.address;
	}
    }

    function initialize()
    { 
	if(null == lat)
	{
	    var geo = google.gears.factory.create('beta.geolocation');
	    geo.getCurrentPosition(SetLocalPosition, handleError);
	}
	else
	{
	    SetMapToLatAndLon(lat, lon);
	}
    }


 
    google.setOnLoadCallback(initialize); 

</script>


<script type="text/javascript" src="/static/json2.js"></script>
<script type="text/javascript">
	//
	// As mentioned at http://en.wikipedia.org/wiki/XMLHttpRequest
	//
	if( !window.XMLHttpRequest ) XMLHttpRequest = function()
	{
		try{ return new ActiveXObject("Msxml2.XMLHTTP.6.0") }catch(e){}
		try{ return new ActiveXObject("Msxml2.XMLHTTP.3.0") }catch(e){}
		try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
		try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){}
		throw new Error("Could not find an XMLHttpRequest alternative.");
	};

	function OnSendFinish(response)
	{
	    if(1 == Number(response))
	    {
		alert('发送成功！');
		document.getElementById('msgtitle').value = "";
		document.getElementById('msgcontent').value = "";
	    }
	    else
	    {
		alert('发送失败！');
	    }
	}

	function OnSendMessage()
	{
	    if(1 > document.getElementById('msgtitle').value.length)
	    {
		alert("请输入发送标题");
		document.getElementById('msgtitle').focus();
		return;
	    }

	    var JsonDictionary = {"tagbox":"fromusershow", "msgtologinname":document.getElementById('msgtologinname').value,
		"msgtonickname":document.getElementById('msgtonickname').value,
		"msgtitle":document.getElementById('msgtitle').value,
		"msgcontent":document.getElementById('msgcontent').value
            };

	    var JsonString = JSON.stringify(JsonDictionary); 

	    var req = new XMLHttpRequest();
	    req.open('POST', '/message_send_rpc', true);
	    req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	    req.setRequestHeader("Content-length", JsonString.length); 
	    req.setRequestHeader("Connection", "close");

	    req.onreadystatechange = function()
	    {
		if(req.readyState == 4 && req.status == 200)
		{
		    var response = null;
		    try
		    {
			response = JSON.parse(req.responseText);
		    }
		    catch (e)
		    {
			response = req.responseText;
		    }

		    OnSendFinish(response);
		}
	    }

	    req.send(JsonString);
	}
</script>




  <table borderColor=#cccccc cellSpacing=0 cellPadding=3 width="100%" bgColor=#ffffff border=2>

    <tr>
	<td>&nbsp;头像：</td>
	<td>
		<img src = "/userphoto?item={{ ShowUserInfo.LoginName }}" width="80px" height="80px" style = "float:left;">
	</td>
    </tr>

    <tr>
	<td>&nbsp;昵称：</td>
	<td>{{ ShowUserInfo.NickName }}</td>
    </tr>

  {% if CanShow %}
	<tr>
	    <td>&nbsp;积分：</td>
	    <td>{{ ShowUserInfo.Integral }}</td>
	</tr>

	<tr>
	    <td>&nbsp;性别：</td>
	    <td>
		{% ifequal ShowUserInfo.Gender 0 %}保密{% endifequal %}
		{% ifequal ShowUserInfo.Gender 1 %}男{% endifequal %}
		{% ifequal ShowUserInfo.Gender 2 %}女{% endifequal %}
	    </td>
	</tr>

	<tr>
	    <td>&nbsp;国家：</td>
	    <td>{{ ShowUserInfo.Country }}</td>
	</tr>
    <tr>
	<td>&nbsp;位置：</td>
	<td>
	        <input type="hidden" id="Latitude" name="Latitude"/>
        	<input type="hidden" id="Longitude" name="Longitude"/>
	        <input type="hidden" id="Address" name="Address">

		<div id="map_canvas" style="width: 500px; height: 300px"></div>
		<div id="human_readable"></div>
	</td>
    </tr>

	<tr>
	    <td>&nbsp;允许别人加为好友：</td>
	    <td>
		{% ifequal ShowUserInfo.AllowFriend 0 %}允许{% endifequal %}
		{% ifequal ShowUserInfo.AllowFriend 1 %}需要该用户同意{% endifequal %}
		{% ifequal ShowUserInfo.AllowFriend 2 %}不允许{% endifequal %}
	    </td>
	</tr>
  {% else %}

    {% ifequal ShowUserInfo.PublicType 2 %}
    <tr>
	<td colSpan=2 align="center"><font color=red>该用户信息未公开</font></td>
    </tr>
    {% else %}
    	{% ifequal ShowUserInfo.PublicType 1 %}
	    {% if NotIsMyFriend %}
		<tr>
		    <td colSpan=2 align="center"><font color=red>该用户信息只有朋友才允许查看</font></td>
		</tr>
	    {% endif %}
	{% endifequal %}
    {% endifequal %}

  {% endif %}
  </table>


  {% if NotIsMyFriend %}
	<p align="center">
	<form action="/friend_add?item={{ ShowUserInfo.key }}" method="post">
		<div align="center">申请加入说明（不能超过200汉字）：<br><textarea name="explain" rows="5" cols="60"></textarea></div>
		<div align="center"><input type="submit" value="成为{{ ShowUserInfo.NickName }}的好友，加入{{ ShowUserInfo.NickName }}的圈子"></div>
	</form>
	</p>
  {% endif %}


  {% if UserName %}
	<p align="center">
	<form action="/message_send?tagbox=fromusershow" method="post">
	    <div align="center">
		<input type="hidden" id="msgtologinname" value="{{ ShowUserInfo.LoginName }}" />
		<input type="hidden" id="msgtonickname" value="{{ ShowUserInfo.NickName }}" />
		给{{ ShowUserInfo.NickName }}发消息<br><br>
		标题：<input type="text" id="msgtitle" size="70"></input><br><br>
		消息内容（不能超过200汉字）：<br><textarea id="msgcontent" rows="5" cols="60"></textarea><br>
		<input type="button" onclick="OnSendMessage()" value="发送">
	    </div>
	</form>
	</p>
  {% endif %}


  <table borderColor=#cccccc cellSpacing=0 cellPadding=3 width="100%" bgColor=#ffffff border=2>

    <tr>
      <td>&nbsp;最新微博</td>
      <td>
	{% for BlogItem in UserBlogs %}
		<p><a href = "/blog?tag=user&user={{ ShowUserInfo.LoginName }}&item={{ BlogItem.key }}">{{ BlogItem.Content|escape }}</a></p>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;最新收藏</td>
      <td>
	{% for Item in UserCollects %}
		<p><a href = "/collect?tag=user&user={{ ShowUserInfo.LoginName }}&item={{ Item.key }}"><b>{{ Item.Title }}</b></a></p>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;最新喜爱</td>
      <td>
	{% for Item in UserLikes %}
		<p><a href = "/like?tag=user&user={{ ShowUserInfo.LoginName }}&item={{ Item.key }}"><b>{{ Item.Title }}</b></a></p>
	{% endfor %}
      </td>
    </tr>

    <tr>
      <td>&nbsp;朋友</td>
      <td>
	<table cellPadding=0 bgColor=#ffffff border=0>
	  <tr>
	    {% for UserItem in UserFriends %}
		<td align="center">
		<a target="_blank" href = "/usershow?item={{ UserItem.FriendName }}">
		<img src = "/userphoto?item={{ UserItem.FriendName }}" width="32px" height="32px">
		</a>
		</td>

		<td>&nbsp;</td>
	    {% endfor %}
	  </tr>

	  <tr>
	    {% for UserItem in UserFriends %}
		<td align="center">
		  <a target="_blank" href = "/usershow?item={{ UserItem.FriendName }}">
			{{ UserItem.FriendName }}
		  </a>
		</td>

		<td>&nbsp;</td>
	    {% endfor %}
	  </tr>
	</table>
      </td>
    </tr>

    </tr>

    <tr>
      <td>&nbsp;使用的工具</td>
      <td>
	{% for ToolItem in HotTools %}
		<a href = "/tool?tag=user&user={{ ShowUserInfo.LoginName }}&item={{ ToolItem.key }}"><b>{{ ToolItem.Title }}</b></a>
	{% endfor %}
      </td>
    </tr>

  </table>

{% endif %}

{% endblock %}